package excel.controller;


import com.github.pagehelper.PageInfo;
import com.usian.model.common.dtos.ResponseResult;
import excel.pojo.Test;
import excel.pojo.User;
import excel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author 秉性哥
 * @createTime 2022/10/27 13:21
 * @description
 */
@CrossOrigin(allowedHeaders = "*")
@RequestMapping("user")
@RestController
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping("findPage")
    public PageInfo findPage(Integer pageIndex, @RequestBody Map serachMap) {
        return userService.findPage(pageIndex, serachMap);
    }

    @PostMapping("add")
    public ResponseResult add(@RequestBody User user) {
        return userService.add(user);
    }

    @PostMapping("edit")
    public ResponseResult edit(@RequestBody User user) {
        return userService.edit(user);
    }

    @GetMapping("findById")
    public ResponseResult findById(Integer id) {
        return userService.findById(id);
    }

    @RequestMapping("del")
    public ResponseResult del(Integer id) {
        return userService.del(id);
    }

    @RequestMapping("poiImport")
    public ResponseResult poiImport() {
        return userService.poiImport();
    }

    @PostMapping("addTest")
    public void addUser(Test test) {
        userService.add(test);
    }

    @RequestMapping("poiExport")
    public ResponseResult poiExport(HttpServletResponse response) {
        return userService.poiExport(response);
    }

    @RequestMapping("poiExportZip")
    public ResponseResult poiExportZip(HttpServletResponse response,Integer pageIndex, @RequestBody Map serachMap) throws IOException {
        return userService.poiExportZip(response,pageIndex, serachMap);
    }

    @GetMapping("poiExportCsv")
    public ResponseResult poiExportCsv(HttpServletResponse response){
        return userService.poiExportCsv(response);
    }

}
